﻿using AspDotNet.Core6.Mvc.ViewComponents.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;

namespace AspDotNet.Core6.Mvc.ViewComponents.Controllers
{
    public class HomeController : Controller
    {
        private readonly ShoppingDbContext dbContext;

        public HomeController(ShoppingDbContext dbContext)
        {
            this.dbContext = dbContext;
            this.dbContext.Database.EnsureCreated();
        }

        public IActionResult Index()
        {
            
            var model = dbContext.Prodcuts!.ToList();
            return View(model);
        }

        public IActionResult IndexViewComponent()
        {
            return ViewComponent("Shopping", new { maxPrice = 2m });
        }

        public async Task<IActionResult> AsyncIndex()
        {
            return View(await dbContext.Prodcuts.ToListAsync());
        }


    }
}